<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								jar包名称 ：<input type="text" name="name"/>
							</li>

							<li>
								备注：<input type="text" name="remark"/>
							</li>

							<li>
								是否全局： <select id="global" name="global">
								<option value="" >全部</option>
								<option value="1" >是</option>
								<option value="0" >否</option>
							</select>


							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="jmeter:jmeterJarMgt:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="jmeter:jmeterJarMgt:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="jmeter:jmeterJarMgt:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="jmeter:jmeterJarMgt:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('jmeter:jmeterJarMgt:edit')}]];
        var removeFlag = [[${@permission.hasPermi('jmeter:jmeterJarMgt:remove')}]];
        var prefix = ctx + "jmeter/jmeterJarMgt";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "jmx脚本依赖jar包管理",
				search: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : 'id',
					visible: false
				},
				{
					field : 'name', 
					title : 'jar包名称（包含版本）',
					sortable: true
				},
				{
					field : 'location', 
					title : '路径',
					sortable: true
				},
				{
					field : 'global',
					title : '是否全局',
					formatter: function(value, row, index) {
						if(value==1){
							return '是';
						}else {
							return '否';
						}
					}
				},
				{
					field : 'caseNames',
					title : '关联用例',
					formatter: function(value, row, index) {
						var actions = [];
						if(row.global==0){
							actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="seeCases(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看关联用例</a> ');
						}
						return actions.join('');
					}
				},
				{
					field : 'createBy', 
					title : '创建者',
					sortable: true
				},
				{
					field : 'createTime', 
					title : '创建时间',
					sortable: true
				},
				{
					field : 'updateBy', 
					title : '更新者',
					sortable: true
				},
				{
					field : 'remark', 
					title : '备注',
					sortable: true
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

		function seeCases(jarId) {
			var row= $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
				return row;
			});

			var url = prefix + "/selectTestCase?jarId="+jarId;
			openFull(jarId,"", url);
		}

		function openFull(jarId,title, url, width, height) {
			//如果是移动端，就使用自适应大小弹窗
			if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
				width = 'auto';
				height = 'auto';
			}
			var index = layer.open({
				type: 2,
				area: [width + 'px', height + 'px'],
				fix: false,
				//不固定
				maxmin: true,
				shade: 0.3,
				title: title,
				content: url,
				btn: ["保存选择用例", '关闭'],
				// 弹层外区域关闭
				shadeClose: true,
				yes: function(index, layero) {
					var iframeWin = layero.find('iframe')[0];
					iframeWin.contentWindow.submitHandler(jarId,index);
					return true;
				},
				cancel: function(index) {
					return true;
				}
			});
			layer.full(index);
		}



	</script>
</body>
</html>